/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package trivia.gui;

import javax.microedition.lcdui.*;
import trivia.Test;

/**
 *
 * @author mourawi
 */
public class ResultsForm extends Form {

    public ResultsForm() {
        super("Results");
        append(new StringItem("You answered ", null));
        append(new StringItem("Your grade is ", null));
        addCommand(new Command("Finish", Command.OK, 0));
        addCommand(new Command("Repeat", Command.BACK, 0));
    }

    public void displayResults(Test test) {
        double result = test.getCorrectAnswers()*100.0/test.getSubject().getProblemsNumber();
        ((StringItem)get(0)).setText(Integer.toString((int)result) + "% questions correctly");
        String grade;
        if(result > 90) {
            grade = "A";
        } else if(result > 70) {
            grade = "B";
        } else if(result > 60) {
            grade = "C";
        } else if(result > 50) {
            grade = "D";
        } else {
            grade = "F";
        }
        ((StringItem)get(1)).setText(grade);
    }
}
